{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $foo == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('article', array('foo' => 'post'));}">添加文章</a></li>
	<li {if $foo == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('article', array('foo' => 'display'));}">文章列表</a></li>
</ul>
<style>
.table td span{display:inline-block;margin-top:4px;}
.table td input{margin-bottom:0;}
</style>
{if $foo == 'display'}
<div class="main">
	<div class="search">
		<form action="site.php" method="get">
		<input type="hidden" name="act" value="module" />
		<input type="hidden" name="do" value="article" />
		<input type="hidden" name="name" value="site" />
		<table class="table table-bordered tb">
			<tbody>
				<tr>
					<th>关键字</th>
					<td>
						<input class="span6" name="keyword" id="" type="text" value="{$_GPC['keyword']}">
					</td>
				</tr>
				<tr>
					<th>分类</th>
					<td>
						<select class="span3" style="margin-right:15px;" name="cate_1" onchange="fetchChildCategory(this.options[this.selectedIndex].value)">
							<option value="0">请选择一级分类</option>
							{loop $category $row}
							{if $row['parentid'] == 0}
							<option value="{$row['id']}" {if $row['id'] == $_GPC['cate_1']} selected="selected"{/if}>{$row['name']}</option>
							{/if}
							{/loop}
						</select>
						<select class="span3" id="cate_2" name="cate_2">
							<option value="0">请选择二级分类</option>
							{if !empty($_GPC['cate_1']) && !empty($children[$_GPC['cate_1']])}
							{loop $children[$_GPC['cate_1']] $row}
							<option value="{$row[0]}" {if $row[0] == $_GPC['cate_2']} selected="selected"{/if}>{$row[1]}</option>
							{/loop}
							{/if}
						</select>
					</td>
				</tr>
				<tr>
				 <tr class="search-submit">
					<td colspan="2"><button class="btn pull-right span2"><i class="icon-search icon-large"></i> 搜索</button></td>
				 </tr>
			</tbody>
		</table>
		</form>
	</div>
	<div style="padding:15px;">
		<table class="table table-hover table-striped">
			<thead class="navbar-inner">
				<tr>
					<th>标题</th>
					<th style="width:180px;">属性</th>
					<th style="width:85px; text-align:right;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $item}
				<tr>
					<td>
						<span class="cate">{if !empty($item['pcate'])}<span class="text-error">[{$category[$item['pcate']]['name']}]</span>{/if}{if !empty($item['ccate'])}<span class="text-info">[{$category[$item['ccate']]['name']}]</span>{/if}</span>
						<a href="{php echo $this->createWebUrl('article', array('foo' => 'post', 'id' => $item['id']))}" style="color:#333;">{$item['title']}</a>
					</td>
					<td>
						{if $item['ishot']}<span class="label label-success">头条</span>{/if}
						{if $item['iscommend']}<span class="label label-success">推荐</span>{/if}
					</td>
					<td style="text-align:right;">
						<a href="{php echo $this->createWebUrl('article', array('foo' => 'post', 'id' => $item['id']))}" title="编辑" class="btn btn-mini"><i class="icon-edit"></i></a>
						<a onclick="return confirm('此操作不可恢复，确认吗？'); return false;" href="{php echo $this->createWebUrl('article', array('foo' => 'delete', 'id' => $item['id']))}" title="删除" class="btn btn-mini"><i class="icon-remove"></i></a>
					</td>
				</tr>
				{/loop}
			</tbody>
			<!--tr>
				<td></td>
				<td colspan="3">
					<input name="token" type="hidden" value="{$_W['token']}" />
					<input type="submit" class="btn btn-primary" name="submit" value="提交" />
				</td>
			</tr-->
		</table>
		{$pager}
	</div>
</div>
<script type="text/javascript">
<!--
	var category = {php echo json_encode($children)};
//-->
</script>
{elseif $foo == 'post'}
<div class="main">
	<form class="form-horizontal form" action="" method="post" enctype="multipart/form-data" onsubmit="return formcheck(this)">
		<input type="hidden" name="id" value="{$item[id]}">
		<h4>文章管理</h4>
		<table class="tb">
			{if !empty($item)}
			<tr>
				<th><label for="">访问地址</label></th>
				<td>
					<a href="{php echo $this->createMobileUrl('detail', array('id' => $item['id'], 'weid' => $_W['weid']))}" target="_blank">{php echo $this->createMobileUrl('detail', array('id' => $item['id'], 'weid' => $_W['weid']))}</a>
					<span class="help-block">您可以根据此地址，添加回复规则，设置访问。</span>
				</td>
			</tr>
			{/if}
			<tr>
				<th><label for="">标题</label></th>
				<td>
					<input type="text" class="span6" placeholder="" name="title" value="{$item['title']}">
				</td>
			</tr>
			<tr>
				<th><label for="">自定义属性</label></th>
				<td>
					<label class="checkbox inline"><input type="checkbox" name="option[hot]" value="1" {if $item['ishot']} checked{/if}> 头条[h]</label>
					<label class="checkbox inline"><input type="checkbox" name="option[commend]" value="1" {if $item['iscommend']} checked{/if}> 推荐[c]</label>
				</td>
			</tr>
			<tr>
				<th><label for="">文章来源</label></th>
				<td>
					<input type="text" class="span3" placeholder="" name="source" value="{$item['source']}">
					<label for="writer" class="checkbox inline" style="margin-right:15px;">文章作者</label>
					<input type="text" class="span2" id="writer" name="author" value="{$item['author']}">
				</td>
			</tr>
			<tr>
				<th><label for="">缩略图</label></th>
				<td>
					<div class="fileupload fileupload-new" data-provides="fileupload">
						<div class="fileupload-preview thumbnail" style="width: 200px; height: 150px;">{if $item['thumb']}<img src="{$_W['attachurl']}{$item['thumb']}" width="200" />{/if}</div>
						<div>
							<span class="btn btn-file"><span class="fileupload-new">选择图片</span><span class="fileupload-exists">更改</span><input name="thumb" type="file" /></span>
							<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">移除</a>
							{if $item['thumb']}<button type="submit" name="fileupload-delete" value="{$item['thumb']}" class="btn fileupload-new">删除</button>{/if}
						</div>
					</div>
					<span class="help-block"></span>
				</td>
			</tr>
			<tr>
				<th><label for="">规则类别</label></th>
				<td>
					<select class="span3" style="margin-right:15px;" name="cate_1" onchange="fetchChildCategory(this.options[this.selectedIndex].value);buildModuleForm($(this.options[this.selectedIndex]).attr('module'));">
						<option value="0">请选择一级栏目</option>
						{loop $category $row}
						{if $row['parentid'] == 0}
						<option value="{$row['id']}" module="{$row['module']}" {if $row['id'] == $item['pcate'] || $row['id'] == $_GPC['pcate']} selected="selected"{/if}>{$row['name']}</option>
						{/if}
						{/loop}
					</select>
					<select class="span3" name="cate_2" id="cate_2" onchange="buildModuleForm($(this.options[this.selectedIndex]).attr('module'));"><option value="0">请选择二级栏目</option>
					{if $item['ccate'] || $item['pcate']}
					{loop $children[$item['pcate']] $row}
						<option value="{$row[0]}" module="{$row[2]}" {if $row[0] == $item['ccate']} selected="selected"{/if}>{$row[1]}</option>
					{/loop}
					{/if}
					</select>
					<input type="hidden" name="module" id="module" value="">
				</td>
			</tr>
			<tr>
				<th>简介</th>
				<td>
					<textarea style="height:200px;" class="span7" name="description" cols="70">{$item['description']}</textarea>
				</td>
			</tr>
			<tr>
				<th></th>
				<td><label class="checkbox inline"><input type="checkbox" name="autolitpic" value="1" checked="true">提取内容的第一个图片为缩略图</label></td>
			</tr>
			<tr>
				<th>内容</th>
				<td>
					<textarea style="height:400px; width:100%;" class="span7 richtext-clone" name="content" cols="70" id="reply-add-text">{$item['content']}</textarea>
				</td>
			</tr>
		</table>

		<table class="tb">
			<tr>
				<th></th>
				<td>
					<button type="submit" class="btn btn-primary span3" name="submit" value="提交">提交</button>
					<input type="hidden" name="token" value="{$_W['token']}" />
				</td>
			</tr>
		</table>
	</form>
</div>
<script type="text/javascript">
<!--
	var category = {php echo json_encode($children)};
	kindeditor($('.richtext-clone'));
//-->
</script>
{/if}
{template 'common/footer'}
